﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LevelEditor.Classes
{
    public class TileGrid
    {
        private GameObject[,] _tiles;
        private int _xLength;
        private int _yLength;

        public TileGrid(int xLength, int yLength)
        {
            _xLength = xLength;
            _yLength = yLength;
            _tiles = new GameObject[xLength, yLength];
        }

        public GameObject this[int x, int y]
        {
            get
            {
                return _tiles[x, y];
            }
            set
            {
                _tiles[x, y] = value;
            }
        }

        public void Clear()
        {
            for(int i = 0; i < _xLength; i++)
            {
                for (int j = 0; j < _yLength; j++)
                {
                    _tiles[i, j] = new GameObject();
                }
            }
        }

        public void ChangeSize(int x, int y)
        {
            GameObject[,] newTiles = new GameObject[x, y];

            // gets the amount of x and y tiles to be copied.
            int maxX = (x > _xLength) ? _xLength : x;
            int maxY = (y > _yLength) ? _yLength : y;

            // if it's a greater size, the new tiles are by default empty.
            // if it's a smaller size, only the tiles that are in that region are copied.
            for (int i = 0; i < maxX; i++)
            {
                for (int j = 0; j < maxY; j++)
                {
                    newTiles[i, j] = _tiles[i, j];
                }
            }
        }
    }
}
